/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;

import Sensors.Sensor;
import Sensors.Temperature;

import morseSide.Decompose;
import morseSide.SocketIn;

/**
 *
 * @author Allan Helbling
 */
public class InterfaceMorseFrameselfIn implements Runnable{

    SocketIn socket;
    BufferedReader in;
    PrintWriter out;
    SpecificCollector speColl;

    public InterfaceMorseFrameselfIn() {
    	// Création du collecteur de Frameself
    	speColl = new SpecificCollector();
    	
        try {
            socket = new SocketIn(InetAddress.getLocalHost(), 60000);
        } catch (IOException ex) {
            System.out.println("Impossible de créer le socket IN");
        }
    }

    public Sensor getMessage() {

            String message_distant = socket.getMessage();
            System.out.println("Message distant : \n" + message_distant);
            Decompose decompose = new Decompose();
            HashMap<String, Integer> param = decompose.getStream(message_distant);
            
            Temperature sensor = new Temperature(param.get("temperature"), "home");
            
            return sensor;
    }

    @Override
    public void run() {
        while (true) {
        	speColl.sendData(getMessage());
        }
    }
}
